<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>轮播图2</title>
    <style>
        .box {
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
        }
        li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        ul {
            height:280px;
            margin: 0;
            padding: 0;
            list-style: none;
        }
        li.current {
            display: block;
        }
        main{
           position:absolute;
           width:200px;
           height:20px;
           top:250px;
           left:160px;
        }
        div{
            width:20px;
            height:20px;
            background-color: yellowgreen;
            border:1px solid black;
            float:left;
            margin-left: 10px;
        }
        .fang{background-color: red;}
    </style>
</head>
<body>
    <section class="box">
        <ul>
            <li class="current"><a href="#"><img src="01.jpg" alt=""></a></li>
            <li><a href="#"><img src="02.jpg" alt=""></a></li>
            <li><a href="#"><img src="03.jpg" alt=""></a></li>
            <li><a href="#"><img src="04.jpg" alt=""></a></li>
            <li><a href="#"><img src="05.jpg" alt=""></a></li>
        </ul>
        <main><div class="fang"></div><div></div><div></div><div></div><div></div></main>
    </section>
    </body>
</html>
<script>
    var lis = document.querySelectorAll("li");
    var index = 0;
    var set=setInterval(changeImage, 1000);
    var d=document.querySelectorAll("div");
    function changeImage() {
        for (var i = 0; i < lis.length||i<d.length;i++){
            lis[i].className = '';
            d[i].className="";
            d[i].index = i;
            //d[n]=i-1; 
            //d[n].className="";
        }
        index++;
        if (index == 5){
            index = 0;
        }
        lis[index].className="current";
        d[this.index].className="fang";
        }
    d[].onmouseenter=function(){
          window.clearTimeout(set);
    // for(var i=0;i<d.length;i++){
        
        //   d[i].className="";
        // d[this.index].className="fang";
        console.log(this.index);
    // d[i].onmouseleave=function(){
    // d[this.index].className="";
    // window.clearTimeout(set);
    // var cet=setInterval(changeImage, 1000);
    // }
    }
    // }
</script>